package com.mianle.userapi.service.task03;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class DynamicTask {

    @Autowired
    private DynamicTaskConfigurer dynamicTaskConfigurer;

    //@org.springframework.scheduling.annotation.Scheduled(cron="0/30 * * * * ?")


    /**
     * 初始化
     */
    //@PostConstruct
    public void loadTasks(){
        log.info("DynamicTask 正在执行......");
        //从数据库查询
        List<TimingTask> tasks = new ArrayList<TimingTask>();
        tasks.add(new TimingTask(1, "0/40 * * * * ?"));
        tasks.add(new TimingTask(2,"0/50 * * * * ?"));
        System.out.println(dynamicTaskConfigurer);
        dynamicTaskConfigurer.refreshTasks(tasks);
    }
}
